package nature.nano.component.part;

import java.util.LinkedHashMap;
import java.util.Map;

import nature.nano.iface.enumer.EnumStringCallback;
import nature.nano.iface.secondary.Configable;

public class SimpleConfigable implements Configable {

	private Map<String, String> props = new LinkedHashMap<String, String>();
	private static final String nil = "null-value";
	
	public void initialize(String... keys) {
		for (String key : keys) {
			props.put(key, nil);
		}
	}

	@Override
	public int enumProp(EnumStringCallback callback) {
		for (String key : props.keySet()) {
			callback.onRead(key);
		}
		return props.size();
	}

	@Override
	public int propCount() {
		return props.size();
	}

	@Override
	public String getProp(String key) {
		String old = props.get(key);
		if (old == null || old == nil) {
			return null;
		}
		return old;
	}

	@Override
	public String setProp(String key, String value) {
		if (!props.containsKey(key)) {
			return null;
		}
		String old = props.put(key, value);
		if (old == nil) {
			return null;
		}
		return old;
	}

	public String prop(String key) {
		return props.get(key);
	}

}
